package xjtu.zd.server.user.myself.dao;

import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import xjtu.zd.server.user.myself.BookDto;
import xjtu.zd.server.user.myself.WorkDto;
import xjtu.zd.server.user.myself.rUser;

import java.util.List;

public interface myDao {
    @Select("select u_id,u_name,u_email,u_sex,u_avatar from t_user where u_id = #{u_id}")
    rUser findNowUser(String u_id);

    @Select("select t_bookshelf.b_id,b_name,b_img,t_bookshelf.ch_id,ch_num from t_bookshelf,t_book,t_chapter " +
            "where t_bookshelf.u_id = #{u_id} " +
            "and t_bookshelf.b_id = t_book.b_id amd t_bookshelf.ch_id = t_chapter.ch_id")
    List<BookDto> findBookShelf(String u_id);

    @Select("select b_id,level,t_book.cla_id,cla_name,b_name,b_img,b_vote,b_score,b_click,b_status from t_book,t_class " +
            "where u_id = #{u_id} and t_book.cla_id = t_class.cla_id")
    List<WorkDto> findWorks(String u_id);

    @Update("update t_user set u_avatar = #{avatar} where u_id = #{uid}")
    void updateAvatar(@Param("uid") String userId, @Param("avatar") String filename);

    @Select("select count(u_id) from t_user where u_email = #{u_email}")
    int ifemailClash(String u_email);

    @Select("select count(u_id) from t_user where u_name = #{u_name}")
    int ifnameClash(String u_name);

    @Update("update t_user set u_name=#{u_name},u_sex=#{u_sex} where u_id=#{u_id}")
    void updateUser(rUser user);
}
